package br.uff.mic1.model;

import java.util.Arrays;

public class MIR {

	public static final int AMUX = 0;
	public static final int COND = 1;
	public static final int ALU = 2;
	public static final int SH = 3;
	public static final int MBR = 4;
	public static final int MAR = 5;
	public static final int RD = 6;
	public static final int WR = 7;
	public static final int ENC = 8;
	public static final int C = 9;
	public static final int B = 10;
	public static final int A = 11;
	public static final int ADDR = 12;
	
	
	private String[] mir = new String[13];
	
	public MIR()
	{
	}
	
	public void setMIR(String value) throws IllegalArgumentException
	{
		if (value.length() > 32)
			throw new IllegalArgumentException("Microinstrucao muito grande");
		
		this.mir[MIR.AMUX] = value.substring(0, 1);
		this.mir[MIR.COND] = value.substring(1, 3);
		this.mir[MIR.ALU] = value.substring(3, 5);
		this.mir[MIR.SH] = value.substring(5, 7);
		this.mir[MIR.MBR] = value.substring(7, 8);
		this.mir[MIR.MAR] = value.substring(8, 9);
		this.mir[MIR.RD] = value.substring(9, 10);
		this.mir[MIR.WR] = value.substring(10, 11);
		this.mir[MIR.ENC] = value.substring(11, 12);
		this.mir[MIR.C] = value.substring(12, 16);
		this.mir[MIR.B] = value.substring(16, 20);
		this.mir[MIR.A] = value.substring(20, 24);
		this.mir[MIR.ADDR] = value.substring(24, 32);
		
	}
	
	public String getCampo(int campo) throws IllegalArgumentException
	{
		if (campo < MIR.AMUX || campo > MIR.ADDR)
			throw new IllegalArgumentException("Campo inexistente na MIR");
		return this.mir[campo];
	}

	@Override
	public String toString() 
	{
		return "MIR [mir=" + Arrays.toString(mir) + "]";
	}
	
	
	
}
